// pages/pingjia/index.js
var app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    ReviewListTwo:[],
    loadingMoreHidden: false,
    currPage: 1,
    pic1:"",
    starArr1: [
      { pic: "/images/nav/star.png", pic2: "/images/nav/star2.png", star: 1 },
      { pic: "/images/nav/star.png", pic2: "/images/nav/star2.png", star: 0 },
      { pic: "/images/nav/star.png", pic2: "/images/nav/star2.png", star: 0 },
      { pic: "/images/nav/star.png", pic2: "/images/nav/star2.png", star: 0 },
      { pic: "/images/nav/star.png", pic2: "/images/nav/star2.png", star: 0 }
    ],
    starArr2: [
      { pic: "/images/nav/star.png", pic2: "/images/nav/star2.png", star: 1 },
      { pic: "/images/nav/star.png", pic2: "/images/nav/star2.png", star: 1 },
      { pic: "/images/nav/star.png", pic2: "/images/nav/star2.png", star: 0 },
      { pic: "/images/nav/star.png", pic2: "/images/nav/star2.png", star: 0 },
      { pic: "/images/nav/star.png", pic2: "/images/nav/star2.png", star: 0 }
    ],
    starArr3: [
      { pic: "/images/nav/star.png", pic2: "/images/nav/star2.png", star: 1 },
      { pic: "/images/nav/star.png", pic2: "/images/nav/star2.png", star: 1 },
      { pic: "/images/nav/star.png", pic2: "/images/nav/star2.png", star: 1 },
      { pic: "/images/nav/star.png", pic2: "/images/nav/star2.png", star: 0 },
      { pic: "/images/nav/star.png", pic2: "/images/nav/star2.png", star: 0 }
    ],
    starArr4: [
      { pic: "/images/nav/star.png", pic2: "/images/nav/star2.png", star: 1 },
      { pic: "/images/nav/star.png", pic2: "/images/nav/star2.png", star: 1 },
      { pic: "/images/nav/star.png", pic2: "/images/nav/star2.png", star: 1 },
      { pic: "/images/nav/star.png", pic2: "/images/nav/star2.png", star: 1 },
      { pic: "/images/nav/star.png", pic2: "/images/nav/star2.png", star: 0 }
    ],
    starArr5: [
      { pic: "/images/nav/star.png", pic2: "/images/nav/star2.png", star: 1 },
      { pic: "/images/nav/star.png", pic2: "/images/nav/star2.png", star: 1 },
      { pic: "/images/nav/star.png", pic2: "/images/nav/star2.png", star: 1 },
      { pic: "/images/nav/star.png", pic2: "/images/nav/star2.png", star: 1 },
      { pic: "/images/nav/star.png", pic2: "/images/nav/star2.png", star: 1 }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
     this.pingjiaList(options.pid)
  },
  
  //获取评价列表
  pingjiaList:function(pid){
    // 获取订单列表
    wx.showLoading();
    var that = this;
    var postDatalist = {
      uid: app.globalData.userInfo.Uid,
      page: that.data.currPage
    };
    wx.request({
      url: app.globalData.host + '/api/store/productreviewlist?pid=' + pid + '&page=' + that.data.currPage,
      success: (res) => {
        wx.hideLoading();
        var ReviewListTwo = [];
        console.log(res.data.Data.ProductReviewList.length)
        if (res.data.Data.ProductReviewList.length > 0) {
          var ReviewList = res.data.Data.ProductReviewList;
          for (var j = 0; j < ReviewList.length; j++) {
                ReviewListTwo.push(ReviewList[j])
            }
          that.setData({
            ReviewListTwo: ReviewListTwo,
            loadingMoreHidden: res.data.Data.PageModel.HasNextPage
          });
        } else {
          this.setData({
            ReviewListTwo: null
          });
        }
      }
    })
  },
  
  //点击图片预览
  previewImage: function (e) {
    var that = this;
    var current = e.target.dataset.src;
    var index = e.target.dataset.index;
    var strip = e.target.dataset.strip;
    wx.previewImage({
      current: current,
      urls: ['https://static.711688.net.cn/upload/user/source/' + that.data.ReviewListTwo[strip].reviewpic_1,
        'https://static.711688.net.cn/upload/user/source/' + that.data.ReviewListTwo[strip].reviewpic_2,
        'https://static.711688.net.cn/upload/user/source/' + that.data.ReviewListTwo[strip].reviewpic_3,
        'https://static.711688.net.cn/upload/user/source/' + that.data.ReviewListTwo[strip].reviewpic_4,
      ]
    })
  },
  loadMorelist: function (e) {
    var that = this;
    if (!that.data.loadingMoreHidden) return;
    var currPage = that.data.CurrentPage;
    that.setData({
      CurrentPage: currPage + 1
    })
    that.pingjiaList(pid);
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  }
})